package com.kmxd.ams.core.exception;

import javax.validation.constraints.NotNull;

/**
 * description
 *
 * @author nickbi
 */
public class BizException extends AbstractException {

  public BizException(
      @NotNull final LogInfo recordInfo, @NotNull String errorCode, String debugMessage) {
    super(recordInfo, errorCode, debugMessage);
    this.code = errorCode;
    this.debugMessage = debugMessage;
  }

  public BizException(@NotNull final LogInfo recordInfo, @NotNull String errorCode) {
    super(recordInfo, errorCode);
    this.code = errorCode;
  }

  public static BizException instance(@NotNull String errorCode) {
    return new BizException(LogInfo.newCallerInstance(), errorCode);
  }

  public static BizException instance(@NotNull String errorCode, String debugMessage) {
    return new BizException(LogInfo.newCallerInstance(), errorCode, debugMessage);
  }

  public static void throwException(@NotNull final LogInfo recordInfo, @NotNull String errorCode) {
    throw new BizException(recordInfo, errorCode);
  }

  public static void throwException(@NotNull String errorCode, String debugMessage) {
    throw new BizException(LogInfo.newCallerInstance(), errorCode, debugMessage);
  }

  @Override
  public String toString() {
    return "BizException{"
        + "code='"
        + code
        + '\''
        + ", msg='"
        + msg
        + '\''
        + ", methodName='"
        + methodName
        + '\''
        + ", className='"
        + className
        + '\''
        + ", debugMessage='"
        + debugMessage
        + '\''
        + "} "
        + super.toString();
  }
}
